package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class FindOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("查找操作");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要查找图书的名字");
        String name = scanner.nextLine();
        Boolean found = false;

        int countnums = bookList.getBookNums();
        Book[] books = new Book[countnums];
        for (int i = 0; i < countnums; i++) {
            books[i] = bookList.getBook(i);
        }

        for (int i = 0; i < books.length; i++) {
            if(books[i]!=null){
                String name1 = books[i].getName();
                if (name1.equals(name)) {
                    System.out.println("找到了");
                    found = true;
                    System.out.println(books[i]);
                    return;
                }
            }
        }
        if(!found){
            System.out.println("没有这本书");
        }
    }
}

